// pages/result/result.js
const app = getApp();
var host = app.globalData.host;
var self = null;

Page({
  data: {
    themeColor: '',
    defaultColor: '',
    borderColor: '',
    list: [],
    info: {},
    ukSchoolId: '',
    ukSchoolName: '',
    cnSchoolId: '',
    majorType: '',
    major: [],
    noResultVisible: false
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
    self.setData({
      cnSchoolId: options.cnSchoolId,
      ukSchoolId: options.ukSchoolId,
      majorType: options.major,
    })
    var cutIndex = app.globalData.majors[options.major].lastIndexOf(" ");
    var major = new Array;
    major.push(app.globalData.majors[options.major].substring(0, cutIndex));
    major.push(app.globalData.majors[options.major].substring(cutIndex));
    self.setData({
      major: major
    })
    wx.request({
      // url: host + '/lx/search/schoolMajor',
      url: host + '/lx/search/schoolMajors',
      data: {
        cnSchoolId: self.data.cnSchoolId,
        ukSchoolId: self.data.ukSchoolId,
        majorType: self.data.majorType
      },
      success: function (res) {
        self.setData({
          list: res.data.info.major,
          ukSchoolName: res.data.info.school.name
        })
        // if (self.data.list.length == 0) {
        //   // wx.showToast({
        //   //   title: '不建议申请',
        //   //   icon: 'none'
        //   // })
        //   wx.request({
        //     url: host + '/lx/search/submit',
        //     data: {
        //       cnSchoolId: self.data.cnSchoolId,
        //       ukSchoolId: self.data.ukSchoolId,
        //       major: self.data.majorType
        //     },
        //     success: function (res) {
        //       var list = res.data.info;
        //       if (list.length > 0) {
        //         self.setData({
        //           info: list[0],
        //           noResultVisible: true
        //         })
        //       }
        //     }
        //   })
        // }
      }
    })
  },
  goInfo: function(e) {
    var id = e.currentTarget.dataset.id;
    var isNoMore = e.currentTarget.dataset.isnomore;
    var name = e.currentTarget.dataset.name;
    var majorRankScoreId = e.currentTarget.dataset.majorrankscoreid;
    if (isNoMore == 1) {
      return;
    }
    if (name.indexOf("Department of") >= 0 || name.indexOf("School") >= 0 || name.indexOf("Institute") >= 0 || name.indexOf("Liverpool Centre") >= 0 || name.indexOf("Planning and Environmental Management Course") >= 0 || name.indexOf("Geography Courses") >= 0) {
      return;
    }
    wx.navigateTo({
      url: '/pages/app/schools/majorInfo/majorInfo?schoolMajorId=' + id + '&schoolId=' + self.data.ukSchoolId + '&majorRankScoreId=' + majorRankScoreId
    })
  }
})